package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.LawFile;
import com.ruoyi.business.service.ILawFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件Controller
 * 
 * @author lwj
 * @date 2021-05-23
 */
@RestController
@RequestMapping("/business/file")
public class LawFileController extends BaseController
{
    @Autowired
    private ILawFileService lawFileService;

    /**
     * 查询文件列表
     */
    @PreAuthorize("@ss.hasPermi('business:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(LawFile lawFile)
    {
        startPage();
        List<LawFile> list = lawFileService.selectLawFileList(lawFile);
        return getDataTable(list);
    }

    /**
     * 导出文件列表
     */
    @PreAuthorize("@ss.hasPermi('business:file:export')")
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LawFile lawFile)
    {
        List<LawFile> list = lawFileService.selectLawFileList(lawFile);
        ExcelUtil<LawFile> util = new ExcelUtil<LawFile>(LawFile.class);
        return util.exportExcel(list, "file");
    }

    /**
     * 获取文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Integer fileId)
    {
        return AjaxResult.success(lawFileService.selectLawFileById(fileId));
    }

    /**
     * 新增文件
     */
    @PreAuthorize("@ss.hasPermi('business:file:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LawFile lawFile)
    {
        return toAjax(lawFileService.insertLawFile(lawFile));
    }

    /**
     * 修改文件
     */
    @PreAuthorize("@ss.hasPermi('business:file:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LawFile lawFile)
    {
        return toAjax(lawFileService.updateLawFile(lawFile));
    }

    /**
     * 删除文件
     */
    @PreAuthorize("@ss.hasPermi('business:file:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Integer[] fileIds)
    {
        return toAjax(lawFileService.deleteLawFileByIds(fileIds));
    }
}
